package com.happy016.controller;


import com.happy016.feign.UserFeignClient;
import com.happy016.feign.UserFeignClientByFallbackFactory;
import com.happy016.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feign/consumer/user")
public class UserFeignConsumerController {

    @Autowired
    private UserFeignClient userFeignClient;
    @Autowired
    private UserFeignClientByFallbackFactory userFeignClientByFallbackFactory;

    /**
     *
     * @author Linyb
     * @since 2017/10/10 15:10
     */
    @GetMapping("/get/{id}")
    public User getUser(@PathVariable Integer id){
        //User user = restTemplate.getForObject("http://localhost:8686/user/get/"+id,User.class);
        User user = userFeignClient.findById(id);
        return user;
    }


    /**
     * 使用FallbackFactory检查回退的原因
     * @author Linyb
     * @since 2017/10/10 15:10
     */
    @GetMapping("/get/factory/{id}")
    public User getUserByFallBackFactory(@PathVariable Integer id){
        //User user = restTemplate.getForObject("http://localhost:8686/user/get/"+id,User.class);
        User user = userFeignClientByFallbackFactory.findById(id);
        return user;
    }
}
